package io.xxx.xbutler.web.controller;

import io.xxx.xbutler.domain.RobotApply;
import io.xxx.xbutler.domain.RobotLogin;
import io.xxx.xbutler.service.RobotService;
import io.xxx.xbutler.web.controller.form.RobotApplyForm;
import io.xxx.xbutler.web.controller.form.RobotBindStoreForm;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/robot")
public class RobotController {

    @Resource
    private RobotService robotService;

    @GetMapping("/login")
    public String login(@RequestParam(required = false) String robotId,
                        @RequestParam(required = false) String robotSerialNo) {
        return robotService.login(robotId, robotSerialNo);
    }

    @GetMapping("/login/qrcode")
    public RobotLogin loginQrcode(@RequestParam String serialNo) {
        return robotService.getLoginQrcode(serialNo);
    }

    /**
     * 申领一个机器人
     */
    @PostMapping("/apply")
    public String apply(@RequestBody @Validated RobotApplyForm form) {
        return robotService.apply(form.to());
    }

    /**
     * 通过点击绑定卡片，绑定机器人和门店的关系
     */
    @PostMapping("/bind_store")
    public void bindStore(@RequestBody RobotBindStoreForm form) {
        robotService.bindStore(form.getRobotId(), form.toStore());
    }

    @GetMapping("/send_bind")
    public void sendBind(@RequestParam Long robotApplyId) {
        robotService.sendBind(robotApplyId);
    }

    /**
     * 查询机器人申请单
     */
    @GetMapping("/apply/get")
    public RobotApply getApply(@RequestParam Long storeId) {
        return robotService.getApply(storeId);
    }
}
